package org.marlin.http.proxy;

import org.marlin.http.handler.HttpHandler;
import org.marlin.http.handler.HttpHandlerAssist;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.factory.FactoryBean;


/**
 * init version 1.5.0
 * @author Jack ZG
 * @since 1.0.0
 */
public class HttpFactoryBean<T>
        implements FactoryBean<T> {
    private Class<T> instance;
    private static HttpServiceRegister x5Registry = new HttpServiceRegister();

    private Map<Class, HttpHandler> httpHandler = (Map) new ConcurrentHashMap<>();


    public HttpFactoryBean() {
    }

    public HttpFactoryBean(Class<T> mapperInterface) {
        this.instance = mapperInterface;
    }


    public T getObject() throws Exception {
        return x5Registry.getHttpInfo(this.instance, this.httpHandler);
    }


    public Class<T> getObjectType() {
        return this.instance;
    }


    public boolean isSingleton() {
        return true;
    }

    public void setInstance(Class<T> instance) {
        this.instance = instance;
    }

    public Class<T> getInstance() {
        return this.instance;
    }


    public void setHttpHandler(HttpHandler httpHandlerBean) {
        this.httpHandler = HttpHandlerAssist.getHttpHandlerMap();
    }
}

